package com.leyou.cart.mq;

import com.leyou.cart.service.impl.cartServiceImpl;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;

import static com.leyou.common.constants.MQConstants.Exchange.Order_EXCHANGE_NAME;
import static com.leyou.common.constants.MQConstants.Queue.*;
import static com.leyou.common.constants.MQConstants.RoutingKey.*;

@Component
public class CartListener {

    @Autowired
    private cartServiceImpl cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = Cart_Delete_QUEUE, durable = "true"),
            exchange = @Exchange(
                    name = Order_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = Cart_Delete_KEY
    ))
    public void listenDelete(Map<Long,List<Long>> idsMap) {
        if (!CollectionUtils.isEmpty(idsMap)) {
       cartService.deleteCartList(idsMap);
        }
    }
}